package com.fr.report.cellElement.core;

import com.fr.base.Style;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.core.GraphHelper;
import com.fr.data.Dictionary;
import com.fr.report.CellElement;
import com.fr.report.cellElement.BarcodeAttr;
import com.fr.report.cellElement.BarcodePresent;
import com.fr.report.cellElement.DictPresent;
import com.fr.report.cellElement.Present;
import com.fr.report.core.PaintUtils;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public class CellUtils
{
  /**
   * @deprecated
   */
  public static Dictionary getDictionary(CellElement paramCellElement)
  {
    Present localPresent = paramCellElement.getPresent();
    if (localPresent instanceof DictPresent)
      return ((DictPresent)localPresent).getDictionary();
    return null;
  }

  /**
   * @deprecated
   */
  public static void setDictionary(CellElement paramCellElement, Dictionary paramDictionary)
  {
    Present localPresent = paramCellElement.getPresent();
    if (localPresent instanceof DictPresent)
      if (paramDictionary == null)
        paramCellElement.setPresent(null);
      else
        ((DictPresent)localPresent).setDictionary(paramDictionary);
    else if (paramDictionary != null)
      paramCellElement.setPresent(new DictPresent(paramDictionary));
  }

  /**
   * @deprecated
   */
  public static BarcodeAttr getBarcodeAttr(CellElement paramCellElement)
  {
    Present localPresent = paramCellElement.getPresent();
    if (localPresent instanceof BarcodePresent)
      return ((BarcodePresent)localPresent).getBarcode();
    return null;
  }

  /**
   * @deprecated
   */
  public static void setBarcodeAttr(CellElement paramCellElement, BarcodeAttr paramBarcodeAttr)
  {
    Present localPresent = paramCellElement.getPresent();
    if (localPresent instanceof BarcodePresent)
      if (paramBarcodeAttr == null)
        paramCellElement.setPresent(null);
      else
        ((BarcodePresent)localPresent).setBarcode(paramBarcodeAttr);
    else if (paramBarcodeAttr != null)
      paramCellElement.setPresent(new BarcodePresent(paramBarcodeAttr));
  }

  public static Image value2ImageWithBackground(Object paramObject, Style paramStyle, int paramInt1, int paramInt2)
  {
    BufferedImage localBufferedImage = GraphHelper.createBufferedImage(paramInt1, paramInt2, 6);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    localGraphics2D.setPaint(Color.white);
    ColorBackground localColorBackground = (paramStyle.getBackground() != null) ? paramStyle.getBackground() : ColorBackground.getInstance(Color.WHITE);
    localColorBackground.paint(localGraphics2D, new Rectangle(paramInt1, paramInt2));
    PaintUtils.paintContent(localGraphics2D, paramObject, paramStyle, paramInt1, paramInt2);
    localBufferedImage.flush();
    localGraphics2D.dispose();
    return localBufferedImage;
  }

  public static Image value2Image(Object paramObject, Style paramStyle, int paramInt1, int paramInt2)
  {
    BufferedImage localBufferedImage = GraphHelper.createBufferedImage(paramInt1, paramInt2, 6);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    localGraphics2D.setPaint(Color.white);
    PaintUtils.paintContent(localGraphics2D, paramObject, paramStyle, paramInt1, paramInt2);
    localBufferedImage.flush();
    localGraphics2D.dispose();
    return localBufferedImage;
  }

  public static Image value2Image(Object paramObject, Style paramStyle, Rectangle paramRectangle1, Rectangle paramRectangle2)
  {
    BufferedImage localBufferedImage = GraphHelper.createBufferedImage(paramRectangle2.width, paramRectangle2.height, 6);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    localGraphics2D.setPaint(Color.white);
    PaintUtils.paintContent(localGraphics2D, paramObject, paramStyle, paramRectangle1, paramRectangle2);
    localBufferedImage.flush();
    localGraphics2D.dispose();
    return localBufferedImage;
  }
}